<?php

/*
 * 原材料新增
 */

namespace Admin\Func;

class Func904020101 {

    var $db;
    var $rst;
    var $errmsg;
    var $MaterialTypeID;
    var $MaterialTypeName;
    var $MaterialTypeDesc;

    public function __construct($MaterialTypeID, $MaterialTypeName, $MaterialTypeDesc) {
        $this->db = new \Think\Model();
        $this->errmsg = '';
        $this->MaterialTypeID = addslashes($MaterialTypeID);
        $this->MaterialTypeName = addslashes($MaterialTypeName);
        $this->MaterialTypeDesc = addslashes($MaterialTypeDesc);
    }

    /*
     * 获取错误信息
     */

    public function getErrMsg() {
        return $this->errmsg;
    }

    /*
     * 验证
     */

    private function validate() {
        $vflag = true;
        $sql = <<<EOD
select * from t_lz_ps_materialtype t where T.MaterialTypeName ='$this->MaterialTypeName'
EOD;

        $rst = $this->db->query($sql);
        if (count($rst) > 0) {
            $this->errmsg = '该类型已存在!';
            $vflag = false;
        } else {
            $vflag = true;
        }
        return $vflag;
    }

    /*
     * 执行
     */

    public function execute() {
        $vflag = true;
        $OperID = I('OperID');
        if ($this->validate()) {

            $sql = <<<EOD
INSERT INTO t_lz_ps_materialtype(
MaterialTypeID,
MaterialTypeName,
MaterialTypeDesc,

        OperID,
        OperDate
        )values(
        '$this->MaterialTypeID',
        '$this->MaterialTypeName',
        '$this->MaterialTypeDesc',

        '$OperID',
        now()
)

EOD;

            //$this->rst = $this->db->query($sql);
            $this->rst = $this->db->execute($sql);
            if ($this->rst === false) {
                $this->errmsg = $this->db->getDbError();
                $vflag = false;
            } else {
                $vflag = true;
            }
        } else {
            $vflag = false;
        }
        return $vflag;
    }

    public function getRst() {
        return $this->rst;
    }

}
